/*
 * $Id: init.c 7557b5d4d82b 2012/12/02 09:07:16 pgurumur $
 *
 * Copyright (c) 2006, 2007, 2008 Prabhu Gurumurthy <pgurumur@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "egpd.h"

void
initvars()
{
   conf = (struct egpd_config *)calloc(1, sizeof(struct egpd_config));
   if (conf == NULL)
      error("%s:%s:%d calloc()", __FILE__, __func__, __LINE__);

   memset(&conf->groups, 0, sizeof(struct egpd_groups));
   LIST_INIT(&conf->groups);

   memset(&conf->pfl, 0, sizeof(struct pfls));
   LIST_INIT(&conf->pfl);

   memset(&conf->policy, 0, sizeof(struct policies));
   LIST_INIT(&conf->policy);
}

struct egpd_group *
new_group()
{
   struct egpd_group *retval = (struct egpd_group *)calloc(1, sizeof(
            struct egpd_group));
   if (retval == NULL)
      error("%s:%s:%d calloc()", __FILE__, __func__, __LINE__);

   retval->remoteas = 0;
   retval->localas = 0;
   retval->type = PEER_UNDEF;

   return retval;
}

char *
new_string(size_t length)
{
   u_int8_t *retval = (u_int8_t *)calloc(length, sizeof(u_int8_t));
   if (retval == NULL)
      error("%s:%s:%d calloc()", __FILE__, __func__, __LINE__);

   return retval;
}

struct prefixlist *
new_prefixlist()
{
   struct prefixlist *retval = (struct prefixlist *)calloc(1, sizeof(
            struct prefixlist));
   if (retval == NULL)
      error("%s:%s:%d calloc()", __FILE__, __func__, __LINE__);

   memset(retval->list, 0, sizeof(struct ipaddr));
   retval->count = 0;
   return retval;
}

struct policy *
new_policy()
{
   struct policy *retval = (struct policy *)calloc(1, sizeof(struct policy));
   if (retval == NULL)
      error("%s:%s:%d calloc()", __FILE__, __func__, __LINE__);

   int ix = 0;
   for (ix = 0; ix < MAXTERMS; ix++)
      memset(&retval->terms[ix], 0, sizeof(struct policy_term));

   retval->termcount = 0;
   return retval;
}
